package common;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Lib {
	static public byte[] readBinFile(String fileName)
	{
		File file = new File(fileName);
        InputStream insputStream = null;
		try {
			insputStream = new FileInputStream(file);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        long length = file.length();
        byte[] bytes = new byte[(int) length];

        try {
			insputStream.read(bytes);
			insputStream.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        return bytes;
	}
	
	static public void writeBinFile(byte[] bytes, String _fileName)
	{
		File file = new File(_fileName);
        OutputStream outsputStream = null;
		try {
			outsputStream = new FileOutputStream(file);
			outsputStream.write(bytes);
			outsputStream.flush();
			outsputStream.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
